package com.cqc.other.ifelse;

public class VUtil {

    public static ThrowExceptionFunction isTrue(boolean flag) {

        return (message) -> {
            if (flag) {
                throw new RuntimeException(message);
            }
        };
    }

    /**
     * isTrue(.)其实相当于 isTrue2(.)
     */
    public static ThrowExceptionFunction isTrue2(boolean flag) {
        ThrowExceptionFunction function = new ThrowExceptionFunction() {
            @Override
            public void throwMessage(String message) {
                if (flag) {
                    throw new RuntimeException(message);
                }
            }
        };
        return function;
    }


    public static BranchHandle isTrueOrFalse(boolean flag) {
        return (trueHandle, falseHandle) -> {
            if (flag) {
                trueHandle.run();
            } else {
                falseHandle.run();
            }
        };
    }
}
